﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components;
using ITAP.ShprossesBuilder.Properties;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationClearSelectedModel : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Очистить выбранную модель"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.Other; }
        }

        public System.Drawing.Image Thumbnail
        {
            get { return Resources.trash; }
        }

        public void Execute(ModelControl modelControl)
        {
            ModelCell activeCell = modelControl.ModelContainer.ActiveCell as ModelCell;
            if (activeCell != null)
            {
                List<IComponent> componentsToRemove = new List<IComponent>();
                foreach (IComponent component in activeCell.Model.InnerComponents)
                {
                    if (!(component is ISpacer))
                        componentsToRemove.Add(component);
                }
                foreach (IComponent component in componentsToRemove)
                    activeCell.Model.RemoveInnerComponent(component);              
            }

            modelControl.UpdateModel();
        }

        public bool CanUndo
        {
            get { return true; }
        }

        #endregion
    }
}
